<template>
  <div>
    <el-form
      style="float: left"
      :inline="true"
      :model="inquire"
      class="demo-form-inline"
    >
      <el-form-item label="发布人员：">
        <el-input v-model="inquire.publisher" placeholder="发布人员"></el-input>
      </el-form-item>
      <el-form-item label="日期：">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="inquire.station"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="inquire.enddate"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="load">查询</el-button>
        <el-button type="primary" @click="dialogTableVisible = true"
          >添加</el-button
        >
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        border=""
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="角色序号" align="center">
        </el-table-column>
        <el-table-column prop="recruitEnterprise" label="招聘企业" align="center">
        </el-table-column>
        <el-table-column prop="recruitPost" label="招聘岗位" align="center">
        </el-table-column>
        <el-table-column prop="educatRequire" label="学历要求" align="center">
        </el-table-column>
        <el-table-column prop="workExperience" label="工作经验" align="center">
        </el-table-column>
        <el-table-column prop="estimatedSalary" label="预计薪资" align="center">
        </el-table-column>
        <el-table-column prop="creationTime" label="创建时间" align="center">
        </el-table-column>
        <el-table-column prop="publisher" label="发布人" align="center">
        </el-table-column>
        <el-table-column prop="isDelete" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.isDelete == 1">未发布</span>
            <span v-if="scope.row.isDelete == 2">已发布</span>
            <span v-if="scope.row.isDelete == 3">已撤销</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="check(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button
              @click="fabu(scope.row)"
              v-if="scope.row.isDelete != 2"
              type="text"
              size="small"
              >发布</el-button
            >
            <el-button
              @click="chexiao(scope.row)"
              v-if="scope.row.isDelete == 2"
              type="text"
              size="small"
              >撤销</el-button
            >
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >删除</el-button
            >
            <el-button type="text" size="small" @click="update(scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="inquire.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="inquire.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>

    <el-dialog title="招聘添加" :visible.sync="dialogTableVisible">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="招聘企业">
          <el-input
            v-model="form.recruitEnterprise"
            placeholder="招聘企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="招聘岗位">
          <el-input
            v-model="form.recruitPost"
            placeholder="招聘岗位"
          ></el-input>
        </el-form-item>
        <br />
        <el-form-item label="学历要求">
          <el-input
            v-model="form.educatRequire"
            placeholder="学历要求"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作经验">
          <el-input
            v-model="form.workExperience"
            placeholder="工作经验"
          ></el-input>
        </el-form-item>
        <br />
        <el-form-item label="预计薪资">
          <el-input
            v-model="form.estimatedSalary"
            placeholder="预计薪资"
          ></el-input>
        </el-form-item>
        <el-form-item label="发布人">
          <el-input v-model="form.publisher" placeholder="发布人"></el-input>
        </el-form-item>
        <br />
        <el-form-item label="职位要求">
          <el-input
            type="textarea"
            style="width: 150%"
            :rows="2"
            placeholder="请输入职位要求"
            v-model="form.jobRequire"
          >
          </el-input>
        </el-form-item>
        <br />
        <el-form-item>
          <el-button type="primary" @click="adds">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="招聘编辑" :visible.sync="dialogupdateVisible">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="招聘企业">
          <el-input
            v-model="form.recruitEnterprise"
            placeholder="招聘企业"
          ></el-input>
        </el-form-item>
        <el-form-item label="招聘岗位">
          <el-input
            v-model="form.recruitPost"
            placeholder="招聘岗位"
          ></el-input>
        </el-form-item>
        <br />
        <el-form-item label="学历要求">
          <el-input
            v-model="form.educatRequire"
            placeholder="学历要求"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作经验">
          <el-input
            v-model="form.workExperience"
            placeholder="工作经验"
          ></el-input>
        </el-form-item>
        <br />
        <el-form-item label="预计薪资">
          <el-input
            v-model="form.estimatedSalary"
            placeholder="预计薪资"
          ></el-input>
        </el-form-item>
        <el-form-item label="发布人">
          <el-input v-model="form.publisher" placeholder="发布人"></el-input>
        </el-form-item>
        <br />
        <el-form-item label="职位要求">
          <el-input
            type="textarea"
            style="width: 150%"
            :rows="2"
            placeholder="请输入职位要求"
            v-model="form.jobRequire"
          >
          </el-input>
        </el-form-item>
        <br />
        <el-form-item>
          <el-button type="primary" @click="xiugai">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="招聘详情" :visible.sync="dialogFormVisible">
      <el-descriptions title="用户信息">
        <el-descriptions-item label="招聘企业">{{
          checks.recruitEnterprise
        }}</el-descriptions-item>
        <el-descriptions-item label="招聘岗位">{{
          checks.recruitPost
        }}</el-descriptions-item>
        <el-descriptions-item label="学历要求">{{
          checks.educatRequire
        }}</el-descriptions-item>
        <el-descriptions-item label="工作经验">{{
          checks.workExperience
        }}</el-descriptions-item>
        <el-descriptions-item label="预计薪资">{{
          checks.estimatedSalary
        }}</el-descriptions-item>
        <el-descriptions-item label="发布人">{{
          checks.publisher
        }}</el-descriptions-item>
        <el-descriptions-item label="职位要求">{{
          checks.jobRequire
        }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>
<script>
import {
  getJobPostingList,
  addRoleManage,
  updateState,
  deleteRoleManage,
  updatefabu,
  updatechexiao,
} from "@/api/parkManage/JobPosting";

export default {
  data() {
    return {
      multipleSelection: [],
      tableData: [],
      inquire: {
        pageIndex: 1,
        pageSize: 2,
        publisher: "",
        station: "",
        enddate: "",
      },
      count: 0,
      state: {
        lightState: false,
      },
      dialogupdateVisible: false,
      dialogFormVisible: false,
      dialogTableVisible: false,
      form: {},
      checks: {},
    };
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      getJobPostingList(this.inquire).then(
        (res) => {
          this.tableData = res.data.data;
          this.count = res.data.totalCount;
        },
        (err) => {
          console.error(err);
        }
      );
    },
    handleClick(row) {
      if (!confirm("确认要删除吗?")) {
        return;
      }
      deleteRoleManage(row).then((res) => {
        if (res.data) {
          this.$message.success("删除成功");
          this.load();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
    handleSizeChange(val) {
      this.inquire.pageSize = val;
      this.load();
    },
    handleCurrentChange(val) {
      this.inquire.pageIndex = val;
      this.load();
    },
    adds() {
      console.log(this.form);
      addRoleManage(this.form).then((res) => {
        if (res.data.data) {
          this.$message.success("添加成功");
          this.load();
          this.dialogTableVisible = false;
        } else {
          this.$message.error("添加失败");
        }
      });
    },
    update(row) {
      this.dialogupdateVisible = true;
      this.form = row;
    },
    check(row) {
      this.dialogFormVisible = true;
      this.checks = row;
    },
    xiugai() {
      updateState(this.form).then((res) => {
        if (res.data) {
          this.$message.success("修改成功");
          this.load();
          this.dialogupdateVisible = false;
        } else {
          this.$message.error("修改失败");
        }
      });
    },
    fabu(row) {
      updatefabu(row).then((res) => {
        if (res.data) {
          this.$message.success("发布成功");
          this.load();
        } else {
          this.$message.error("发布失败");
        }
      });
    },
    chexiao(row) {
      updatechexiao(row).then((res) => {
        if (res.data) {
          this.$message.success("撤销成功");
          this.load();
        } else {
          this.$message.error("撤销失败");
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style></style>